<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增商品规格')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-size-add">
            <div class="form-group">
                <label class="col-sm-3 control-label">大分类：</label>
                <div class="col-sm-8">
                    <select name="typeParentId" class="typeParentId form-control" onchange="typeParentChange()"><option value="">全部</option></select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">小分类：</label>
                <div class="col-sm-8">
                    <select name="typeId" class="typeId form-control" required><option value="">全部</option></select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">规格名称：</label>
                <div class="col-sm-8">
                    <input name="sizeName" class="form-control" type="text" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <th:block th:include="include :: jquery-cxselect-js" />
    <script th:inline="javascript">
        var prefix = ctx + "baseInfo/size"
        $("#form-size-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-size-add').serialize());
            }
        }

        //大分类
        var typeParentData = [[${parentType}]];
        $('#form-size-add').cxSelect({
            required: false,
            firstTitle: '全部',
            selects: ['typeParentId'],
            jsonName: 'name',
            jsonValue: 'id',
            data: typeParentData
        });

        //大分类选中
        function typeParentChange() {
            var typeParentId = $(".typeParentId").val();
            $.ajax({
                type: "post",
                url: ctx + "baseInfo/product/parentTypeChange",
                data: {
                    "parentId": typeParentId,
                    "typeLevel": "2"
                },
                success: function(result) {
                    if (result.code == 0) {
                        $('#form-size-add').cxSelect({
                            required: false,
                            firstTitle: '全部',
                            selects: ['typeId'],
                            jsonName: 'name',
                            jsonValue: 'id',
                            data: result.data.typeList
                        });
                    }
                }
            })
        }
    </script>
</body>
</html>